package com.kwok.rbac.application.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwok.rbac.application.common.utils.R;
import com.kwok.rbac.application.entity.SystemUser;
import com.kwok.rbac.application.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-05-25
 */
@RestController
@RequestMapping("/systemUser")
public class SystemUserController {

    @Autowired
    private SystemUserService systemUserService;

    //添加系统用户
    @PostMapping("/save")
    public R saveSystemUser(@RequestBody SystemUser systemUser){
        return R.write(systemUserService.save(systemUser));
    }

    //批量添加系统用户
    @PostMapping("/batchSave")
    public R batchSaveSystemUser(@RequestBody List<SystemUser> systemUserList){
        return R.write(systemUserService.saveBatch(systemUserList));
    }

    //根据主键查询单个系统用户
    @GetMapping("/get/{userId}")
    public R getSystemUserById(@PathVariable Integer userId){
        return R.success(systemUserService.getById(userId));
    }

    //查询所有系统用户
    @GetMapping("/list")
    public R getAllSystemUser(){
        return R.success(systemUserService.list());
    }

    //分页查询系统用户
    @PostMapping("/userPage")
    public Page<SystemUser> systemUserPage(@RequestBody Page<SystemUser> page){
        Page<SystemUser> systemUserPage = systemUserService.page(page);
        return systemUserPage;
    }

    //根据主键修改系统用户信息
    @PutMapping("/update")
    public R updateSystemUser(@RequestBody SystemUser systemUser){
        return R.write(systemUserService.updateById(systemUser));
    }

    //根据主键删除系统用户
    @DeleteMapping("/{userId}")
    public R removeSystemUserById(@PathVariable Integer userId){
        return R.write(systemUserService.removeById(userId));
    }

    //根据主键批量删除系统用户
    @DeleteMapping
    public R batchRemoveSystemUser(@RequestBody List<Integer> userIdList){
        return R.write(systemUserService.removeByIds(userIdList));
    }

}
